package arrray;

/**
 * @author huangxianjin
 * @date 2025/8/28 23:10
 * @description "最长公共前缀"
 */
public class LC_14 {
    //自己的做法
    public String longestCommonPrefix(String[] strs) {
        String str = strs[0];
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < str.length(); i++) {
            sb.append(str.charAt(i));
            int count = 0;
            for (int j = 1; j < strs.length; j++) {
                if (i < strs[j].length() && strs[j].charAt(i) == str.charAt(i)) {
                    count++;
                }
            }
            if (count != strs.length - 1) {
                return sb.substring(0, sb.length() - 1);
            }
        }
        return sb.toString();
    }
}
